package com.atguigu.spring5.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

/**
 * @author : wenchao.long
 * @date : Created in 2020/10/29 15:04 周四
 * @description :
 */
@Configuration
@PropertySource("classpath:jdbc.properties")
@ComponentScan(basePackages = "com.atguigu.spring5.*")
public class DataSourceConfig {

    @Value("${prop.driverClass}")
    private String driverClass;

    @Value("${prop.url}")
    private String url;

    @Value("${prop.userName}")
    private String userName;

    @Value("${prop.password}")
    private String password;

    @Bean
    public DruidDataSource getDruidDateSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClass);
        dataSource.setUrl(url);
        dataSource.setUsername(userName);
        dataSource.setPassword(password);
        return dataSource;
    }
}
